package com.json.controller;

import com.alibaba.fastjson2.JSON;
import com.json.service.StudentService;
import com.json.service.impl.StudentServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/update")
public class StudentUpdate extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws SecurityException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json:charset=UTF-8");
        String name = req.getParameter("name");
        int age = Integer.parseInt(req.getParameter("age"));
        String cellphone = req.getParameter("cellphone");
        String address = req.getParameter("address");
        String gender = req.getParameter("gender");
        Integer id = Integer.parseInt(req.getParameter("id"));
        StudentService studentService = new StudentServiceImpl();
        if (studentService.update(name,age,cellphone,address,gender,id)){
            resp.getWriter().write(JSON.toJSONString("修改成功"));
        }
        else {
            resp.getWriter().write(JSON.toJSONString("修改失败"));
        }

    }
}
